import Main;
import nme.display.Bitmap;
import nme.display.Loader;
import nme.events.Event;
import nme.media.Sound;
import nme.net.URLLoader;
import nme.net.URLRequest;
import nme.Assets;


class ApplicationMain {
	
	
	private static var completed:Int;
	private static var total:Int;
	
	public static var loaders:Hash <Loader>;
	public static var urlLoaders:Hash <URLLoader>;
	
	
	public static function main () {
		
		completed = 0;
		loaders = new Hash <Loader> ();
		urlLoaders = new Hash <URLLoader> ();
		total = 0;
		
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/NO.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/ResetSavedData.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Credits.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/MainMenu.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/audioMute.png", loader);
		total ++;
		
		
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Yes.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/BLAAMMute.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Options.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/StartButton.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Back.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/audio.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Menu.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/button.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/TextBackground.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Background.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/ContinueGame.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/icon.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/Instructions.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/CircleBackground.png", loader);
		total ++;
		
		
		var loader:Loader = new Loader ();
		loaders.set ("assets/BLAAM.png", loader);
		total ++;
		
		
		if (total == 0) {
			
			begin ();
			
		} else {
			
			for (path in loaders.keys ()) {
				
				var loader:Loader = loaders.get (path);
				loader.contentLoaderInfo.addEventListener ("complete", loader_onComplete);
				loader.load (new URLRequest (path));
				
			}
			
			for (path in urlLoaders.keys ()) {
				
				var urlLoader:URLLoader = urlLoaders.get (path);
				urlLoader.addEventListener ("complete", loader_onComplete);
				urlLoader.load (new URLRequest (path));
				
			}
			
		}
		
	}
	
	
	private static function begin ():Void {
		
		Main.main ();
		
	}
	

   public static function getAsset(inName:String):Dynamic {
	   
		
		if (inName=="assets/NO.png") {
			
			return Assets.getBitmapData ("assets/NO.png");
			
		}
		
		if (inName=="assets/ResetSavedData.png") {
			
			return Assets.getBitmapData ("assets/ResetSavedData.png");
			
		}
		
		if (inName=="assets/Credits.png") {
			
			return Assets.getBitmapData ("assets/Credits.png");
			
		}
		
		if (inName=="assets/MainMenu.png") {
			
			return Assets.getBitmapData ("assets/MainMenu.png");
			
		}
		
		if (inName=="assets/audioMute.png") {
			
			return Assets.getBitmapData ("assets/audioMute.png");
			
		}
		
		if (inName=="assets/Background.mp3") {
			
			return Assets.getSound ("assets/Background.mp3");
			
		}
		
		if (inName=="assets/Yes.png") {
			
			return Assets.getBitmapData ("assets/Yes.png");
			
		}
		
		if (inName=="assets/BLAAMMute.png") {
			
			return Assets.getBitmapData ("assets/BLAAMMute.png");
			
		}
		
		if (inName=="assets/Options.png") {
			
			return Assets.getBitmapData ("assets/Options.png");
			
		}
		
		if (inName=="assets/StartButton.png") {
			
			return Assets.getBitmapData ("assets/StartButton.png");
			
		}
		
		if (inName=="assets/Back.png") {
			
			return Assets.getBitmapData ("assets/Back.png");
			
		}
		
		if (inName=="assets/audio.png") {
			
			return Assets.getBitmapData ("assets/audio.png");
			
		}
		
		if (inName=="assets/Menu.png") {
			
			return Assets.getBitmapData ("assets/Menu.png");
			
		}
		
		if (inName=="assets/button.png") {
			
			return Assets.getBitmapData ("assets/button.png");
			
		}
		
		if (inName=="assets/TextBackground.png") {
			
			return Assets.getBitmapData ("assets/TextBackground.png");
			
		}
		
		if (inName=="assets/Background.png") {
			
			return Assets.getBitmapData ("assets/Background.png");
			
		}
		
		if (inName=="assets/ContinueGame.png") {
			
			return Assets.getBitmapData ("assets/ContinueGame.png");
			
		}
		
		if (inName=="assets/icon.png") {
			
			return Assets.getBitmapData ("assets/icon.png");
			
		}
		
		if (inName=="assets/Instructions.png") {
			
			return Assets.getBitmapData ("assets/Instructions.png");
			
		}
		
		if (inName=="assets/CircleBackground.png") {
			
			return Assets.getBitmapData ("assets/CircleBackground.png");
			
		}
		
		if (inName=="assets/BLAAM.png") {
			
			return Assets.getBitmapData ("assets/BLAAM.png");
			
		}
		
		return null;
		
   }
   
   
   
   
   // Event Handlers
   
   
   
   
	private static function loader_onComplete (event:Event):Void {
	   
		completed ++;
		
		if (completed == total) {
			
			begin ();
			
		}
	   
	}
   
   
}



	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	

	
